package jsf;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ex01")
public class ex01_tabuada extends HttpServlet {

	private static final long serialVersionUID = 2165160604915514115L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		String nrValor = request.getParameter("valor");
		int i;
		PrintWriter out;
		try {
			out = response.getWriter();
			response.setContentType("text/html");
			
			out.println("<html><body>");
			if (nrValor == null) {
				out.println("<h3>Valor não informado (parâmetro: valor)!</h3>");
			}
			else {
				out.println("<h1>Tabuada do número: " + nrValor+ "</h1>");
				out.println("<table width=200 border=1 style='border-collapse:collapse'>");
				
				for (i=0; i<=10; i++) {
					out.println("<tr>");
					out.println("<td align='center'> "+nrValor+" </td>");
					out.println("<td align='center'> X </td>");
					out.println("<td align='center'> " +i+ "</td>");
					out.println("<td> = "+ Integer.parseInt(nrValor) * i+"</td>");
					out.println("</tr>");
				}
				out.println("</table>");
			}
			out.println("</body></html>");
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}